package com.sfx.concurrent.demo.concurrent.pattern.GuardedObjectEncapsulationTest;

import lombok.extern.slf4j.Slf4j;

/**
 * Created with IntelliJ IDEA.
 * Description:邮寄员线程用于送信
 * User: sfx
 * Date: 2023-01-01
 * Time: 10:28
 */

@Slf4j(topic = "c.Postman")
public class Postman extends Thread {

    //送信的id
    private int id;
    //送信的mail
    private String mail;

    public Postman(int id, String mail) {
        this.id = id;
        this.mail = mail;
    }

    @Override
    public void run() {
        //通过id获取到GuardedObject
        GuardedObject guardedObject = MailBoxes.getGuardedObject(id);
        log.debug("送完信id{},mail{}",this.id,this.mail);
        guardedObject.complete(mail);
    }
}